import "nprogress/nprogress.css";
import { start, done, configure } from "nprogress";

configure({
  trickleSpeed: 20,
  showSpinner: false,
});
// const delay = (time) =>
//   new Promise((resolve) => {
//     setTimeout(() => {
//       resolve();
//     }, time);
//   });

const getAsyncComponent = (asyncCompFun) => {
  return async () => {
    start();
    const comp = await asyncCompFun();
    done();
    return comp;
  };
};

export default [
  // 根路径重定向到登录页
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/loading",
    name: "Loading",
    component: getAsyncComponent(() => import("@/views/Loading")),
    meta: {
      title: "加载中",
    },
  },
  {
    path: "/home",
    name: "Home",
    component: getAsyncComponent(() => import("@/views/Home")),
    meta: { title: "首页" },
  },
  {
    path: "/about",
    name: "About",
    component: getAsyncComponent(() => import("@/views/About")),
    meta: { title: "关于我的" },
  },
  {
    path: "/article",
    name: "Blog",
    component: getAsyncComponent(() => import("@/views/Blog")),
    meta: { title: "文章" },
  },
  {
    path: "/article/cate/:categoryId",
    name: "CategoryBlog",
    component: getAsyncComponent(() => import("@/views/Blog")),
    meta: { title: "文章" },
  },
  {
    path: "/article/:id",
    name: "BlogDetail",
    component: getAsyncComponent(() => import("@/views/Blog/Detaile")),
    meta: { title: "文章详情" },
  },

  {
    path: "/project",
    name: "Project",
    component: getAsyncComponent(() => import("@/views/Project")),
    meta: { title: "项目&效果" },
  },
  {
    path: "/message",
    name: "Message",
    component: getAsyncComponent(() => import("@/views/Message")),
    meta: { title: "留言板" },
  },
  {
    path: "*",
    name: "NotFound",
    component: getAsyncComponent(() => import("@/components/NotFound")),
    meta: { title: "404 Not Found" },
  },
];
